package com.ringtheweb.persistence.dao.jpa;

import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.ringtheweb.model.Role;
import com.ringtheweb.persistence.dao.IRoleDAO;

/**
 * JPA implementation of {@link IRoleDAO}
 * @author ldewavri
 *
 */
@Repository("roleDAO")
public class RoleDAO extends GenericJPADAO<Role, Long> 
		implements IRoleDAO{

	@Override
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	public Role findByName(String name) {
		Role dbRole = null;
		
		try {
			dbRole = (Role)getEntityManager().createNamedQuery("rolesByName").
				setParameter("name", name).getSingleResult();
		}
		catch(NoResultException e) {
			//
		}
		catch(NonUniqueResultException e) {
			//
		}
		
		return dbRole;
	}
	



}
